package com.example.goodsmanagementcabinet.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.goodsmanagementcabinet.R;
import com.example.goodsmanagementcabinet.bean.UserBean;
import com.example.goodsmanagementcabinet.otto.OttoManager;
import com.example.goodsmanagementcabinet.otto.OttoMsg;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;


public class KeyUserAdapter extends BaseAdapter {
    private Context mContext;
    private List mArrayList = new ArrayList();

    private boolean isIntent = false;

    public boolean isIntent() {
        return isIntent;
    }

    public KeyUserAdapter(Context context) {
        this.mContext = context;
    }

    public void notifyRefresh(List<UserBean> list) {
        mArrayList.clear();
        mArrayList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return (mArrayList != null && mArrayList.size() == 0) ? 0 : mArrayList.size();
    }

    @Override
    public Object getItem(int arg0) {
        return mArrayList.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        return arg0;
    }

    @Override
    public View getView(final int position, View currentView, ViewGroup arg2) {
        HolderView holderView = null;
        if (currentView == null) {
            holderView = new HolderView();
            currentView = LayoutInflater.from(mContext).inflate(R.layout.item_bind_userlist, arg2, false);
            holderView.mNameTv = (TextView) currentView.findViewById(R.id.tv_name);
            holderView.mNoTv = (TextView) currentView.findViewById(R.id.tv_no);
            holderView.mRelativeR = (LinearLayout) currentView.findViewById(R.id.mRelativeR);
            currentView.setTag(holderView);
        } else {
            holderView = (HolderView) currentView.getTag();
        }
        final UserBean myuser = (UserBean) mArrayList.get(position);
        if (myuser != null) {
            holderView.mNameTv.setText(myuser.getNickname());
            holderView.mNoTv.setText(myuser.getUserId());
        }
        holderView.mRelativeR.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OttoManager.getInstance().deliverMsg(OttoMsg.OTTO_BIND_USER, myuser);
            }
        });
        return currentView;

    }

    public class HolderView {
        private TextView mNameTv, mNoTv;
        private LinearLayout mRelativeR;

    }


}
